package com.panny.newcar.util;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.Connection;

public class ConnectionProxy implements InvocationHandler {
	Connection delegate;

	ConnectionProxy(Connection delegate) {
		this.delegate = delegate;
	}

	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		try {
			if ("close".equals(method.getName())) {
				ConnectionPool.returnConnection((Connection) proxy);
			} else
				return method.invoke(delegate, args);
		} catch (Exception e) {
		}
		return null;
	}
}